package com.cn.xc.utils;

import java.util.Collection;

/**
 * FUN: collection tools class
 * 
 * @author sushy
 * @date 2016-3-23
 */
public class CollectionUtil {

	/**
	 * //# judge a collection whether is null or empty
	 * 
	 * @param collection
	 * @return boolean
	 */
	public static boolean isEmpty(Collection<?> collection) {
		return collection == null || collection.isEmpty();
	}

	/**
	 * //# judge a collection whether is not null and non-null
	 * 
	 * @param collection
	 * @return boolean
	 */
	public static boolean isNotEmpty(Collection<?> collection) {
		return !CollectionUtil.isEmpty(collection);
	}

	/**
	 * //# get first element from collection
	 * 
	 * @param <T>
	 * @param collection
	 * @return T element
	 */
	public static <T> T getFirst(Collection<T> collection) {
		return isEmpty(collection) ? null : collection.iterator().next();
	}

}
